#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <strings.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <stdlib.h>



int main(int argc, char *argv[])
{
  int sockfd, ret;
  char buffer[1024];
  struct sockaddr_in sock;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (0 > sockfd)
  {
    fprintf(stderr,"socket_error, error code id %d\n", errno);
    exit(-1);
  }
  bzero(&sock, sizeof(sock));
  sock.sin_family=AF_INET;
  sock.sin_port=htons(10000);
  ret = inet_pton(AF_INET, argv[1], &sock.sin_addr);
  if (0 >= ret)
  {
    fprintf(stderr, "parse address error, error code=%d\n", errno);
    exit(-1);
  }
  ret = connect(sockfd, reinterpret_cast<struct sockaddr *>(&sock), sizeof(sock));
  if (0 > ret)
  {
    fprintf(stderr, "connect failed error code=%d\n", errno);
    exit(-1);
  }

  while((ret = read(sockfd, buffer, 1023)) > 0)
  {
    buffer[ret] = 0;
    fprintf(stderr, "%s\n", buffer);
    sleep(100);
  }
  exit(0);
}
